﻿using System;
using System.Linq;
using System.Text;

namespace MinesweeperUtility
{
    public class Timer
    {
        public System.Diagnostics.Stopwatch Time { get; private set; }

        public Timer()
        {
            this.Time = new System.Diagnostics.Stopwatch();
        }

        public void StartTimer()
        {
            this.Time.Start();
        }

        public void StopTimer()
        {
            this.Time.Stop();
        }

        public long GetTime()
        {
            return (long)this.Time.ElapsedMilliseconds;
        }

        public override string ToString()
        {
            int minutes = (int)(this.Time.ElapsedMilliseconds / 60000);
            int seconds = (int)(this.Time.ElapsedMilliseconds / 1000) - minutes * 60;
            StringBuilder sb = new StringBuilder();
            sb.Append(string.Format("{0,2}", minutes));
            sb.Append(" : ");
            sb.Append(string.Format("{0,2:00}", seconds));
            return sb.ToString();
        }

    }
}